﻿namespace Microsoft.Services.TestTools.UITesting.Html{
    using System;
    using System.Reflection;

    
    public static class ObjectExtensions {
     
        public static void ForEachProperty(this object self, Action<string, string> action) {
            var props = self.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
            foreach (var prop in props) {
                var val = string.Empty;
                try
                {
                    val = prop.GetValue(self, null) == null ? string.Empty : prop.GetValue(self, null).ToString();
                }
                catch (Exception)
                {
                   
                }
               
                action(prop.Name, val);
            }
        }
    }
}